package com.example.hp.yuejian5.activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Window;
import android.widget.TextView;

import com.example.hp.yuejian5.R;
import com.example.hp.yuejian5.RetrofitListener.RetrofitListener;
import com.example.hp.yuejian5.bean.CourseBean;
import com.example.hp.yuejian5.model.Course_DetailModel;
import com.squareup.picasso.Picasso;

public class Course_DetailActivity extends AppCompatActivity {
    private String i_id, u_id;
    private Context context;
    private RetrofitListener<CourseBean> listener;
    private SharedPreferences sp;
    private TextView course_detail_name, course_detail_intro,course_detail_price,course_detail_level;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_course_detail);
        Intent intent = getIntent();
        i_id = (String) intent.getStringExtra("c_id");
        sp = getSharedPreferences("user_id", Context.MODE_PRIVATE);
        u_id = sp.getString("userid", null);
        initView();

        listener = new RetrofitListener<CourseBean>() {
            @Override
            public void onSuccess(CourseBean courseBean, int flag) {
                course_detail_name.setText(courseBean.getCourse_name());
                course_detail_intro.setText(courseBean.getCourse_intro());
                course_detail_price.setText(courseBean.getCourse_price());
                course_detail_level.setText(courseBean.getCourse_level());
            }

            @Override
            public void onFail() {

            }
        };


        courseDetail();

    }

    private void initView() {
        course_detail_name = findViewById(R.id.course_detail_name);
        course_detail_intro = findViewById(R.id.course_detail_intro);
        course_detail_price = findViewById(R.id.course_detail_price);
        course_detail_level = findViewById(R.id.course_detail_level);
    }


    private void courseDetail() {
        Course_DetailModel course_detailModel = new Course_DetailModel();
        course_detailModel.courseDetail(i_id, listener);
    }



}
